home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / Clueless.swf / scripts / ClothingSlot.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  5.1 KB  |  197 lines

  1. package
  2. {
  3.    import caurina.transitions.Tweener;
  4.    import flash.display.DisplayObject;
  5.    import flash.display.DisplayObjectContainer;
  6.    import flash.display.MovieClip;
  7.    import flash.events.MouseEvent;
  8.    import flash.geom.Point;
  9.    import flash.geom.Rectangle;
  10.    
  11.    [Embed(source="/_assets/assets.swf", symbol="ClothingSlot")]
  12.    public class ClothingSlot extends MovieClip
  13.    {
  14.        
  15.       
  16.       internal var _nTriggerDist:Number;
  17.       
  18.       internal var _pOriginalPosition:Point;
  19.       
  20.       internal var _nRestY:Number;
  21.       
  22.       internal var _nRestX:Number;
  23.       
  24.       internal var _pSize:Point;
  25.       
  26.       public var _filler:ClothingSlotFiller;
  27.       
  28.       internal var _nInitialY:Number;
  29.       
  30.       internal var _nInitialX:Number;
  31.       
  32.       public function ClothingSlot()
  33.       {
  34.          super();
  35.          _pSize = new Point(width,height);
  36.          _pOriginalPosition = new Point(x,y);
  37.       }
  38.       
  39.       public static function extractFromStage(param1:DisplayObjectContainer) : Array
  40.       {
  41.          var _loc2_:int = 0;
  42.          var _loc3_:Array = null;
  43.          var _loc4_:DisplayObject = null;
  44.          _loc2_ = 0;
  45.          _loc3_ = new Array();
  46.          _loc2_ = 0;
  47.          while(_loc2_ < param1.numChildren)
  48.          {
  49.             if((_loc4_ = param1.getChildAt(_loc2_)) is ClothingSlot)
  50.             {
  51.                _loc3_.push(_loc4_);
  52.             }
  53.             _loc2_++;
  54.          }
  55.          return _loc3_.sortOn("name");
  56.       }
  57.       
  58.       protected function onMouseMove(param1:MouseEvent) : void
  59.       {
  60.          var _loc2_:Number = NaN;
  61.          var _loc3_:Number = NaN;
  62.          _loc2_ = calcDist(mouseX,mouseY,_nRestX,_nRestY);
  63.          if(_loc2_ < 2 * _nTriggerDist)
  64.          {
  65.             if(_loc2_ > _nTriggerDist)
  66.             {
  67.                _loc3_ = (_loc2_ - _nTriggerDist) / _nTriggerDist;
  68.             }
  69.             else
  70.             {
  71.                x = _nInitialX;
  72.                y = _nInitialY;
  73.             }
  74.          }
  75.          else
  76.          {
  77.             x = _nRestX;
  78.             y = _nRestY;
  79.          }
  80.       }
  81.       
  82.       public function clean() : void
  83.       {
  84.          while(numChildren > 1)
  85.          {
  86.             if(getChildAt(0).alpha == 0)
  87.             {
  88.                removeChildAt(1);
  89.             }
  90.             else
  91.             {
  92.                removeChildAt(0);
  93.             }
  94.          }
  95.       }
  96.       
  97.       public function getPart() : Part
  98.       {
  99.          var _loc1_:int = 0;
  100.          _loc1_ = 0;
  101.          while(_loc1_ < numChildren)
  102.          {
  103.             if(getChildAt(_loc1_) is Part)
  104.             {
  105.                return getChildAt(_loc1_) as Part;
  106.             }
  107.             _loc1_++;
  108.          }
  109.          return null;
  110.       }
  111.       
  112.       public function setHiddenAndClickable() : void
  113.       {
  114.          _filler.alpha = 0;
  115.       }
  116.       
  117.       public function hasPart() : Boolean
  118.       {
  119.          return getPart() != null;
  120.       }
  121.       
  122.       public function setRest(param1:Number, param2:Number) : void
  123.       {
  124.          _nRestX = param1;
  125.          _nRestY = param2;
  126.          _nInitialX = x;
  127.          _nInitialY = y;
  128.          _nTriggerDist = calcDist(x,y,param1,param2);
  129.          parent.addEventListener(MouseEvent.MOUSE_MOVE,onMouseMove,false,0,true);
  130.       }
  131.       
  132.       public function slideIn() : void
  133.       {
  134.          var _loc1_:Part = null;
  135.          var _loc2_:Number = NaN;
  136.          var _loc3_:Rectangle = null;
  137.          var _loc4_:Number = NaN;
  138.          _loc1_ = getPart();
  139.          if(_loc1_ != null)
  140.          {
  141.             Tweener.removeTweens(_loc1_,[x]);
  142.             _loc1_.center();
  143.             _loc2_ = _loc1_.x;
  144.             _loc3_ = this.getBounds(stage);
  145.             y = _pOriginalPosition.y;
  146.             if(_loc3_.x > this.stage.stageWidth / 2)
  147.             {
  148.                _loc1_.x += 150;
  149.             }
  150.             else
  151.             {
  152.                _loc1_.x -= 150;
  153.             }
  154.             _loc4_ = 0.5 + Math.random() * 2;
  155.             Tweener.addTween(_loc1_,{
  156.                "x":_loc2_,
  157.                "time":_loc4_,
  158.                "transition":"easeoutelastic"
  159.             });
  160.          }
  161.       }
  162.       
  163.       public function isPointInRect(param1:Number, param2:Number) : Boolean
  164.       {
  165.          if(param1 < x || param1 > x + _pSize.x)
  166.          {
  167.             return false;
  168.          }
  169.          if(param2 < y || param2 > y + _pSize.y)
  170.          {
  171.             return false;
  172.          }
  173.          return true;
  174.       }
  175.       
  176.       protected function calcDist(param1:Number, param2:Number, param3:Number, param4:Number) : Number
  177.       {
  178.          return Math.sqrt((param1 - param3) * (param1 - param3) + (param2 - param4) * (param2 - param4));
  179.       }
  180.       
  181.       public function pickupPart() : Part
  182.       {
  183.          var _loc1_:Part = null;
  184.          var _loc2_:Point = null;
  185.          _loc1_ = getPart();
  186.          if(_loc1_ != null)
  187.          {
  188.             _loc2_ = _loc1_.parent.localToGlobal(new Point(0,0));
  189.             _loc1_.Pose = ModelPose.DEFAULT;
  190.             Tweener.removeTweens(_loc1_,[x,y]);
  191.             clean();
  192.          }
  193.          return _loc1_;
  194.       }
  195.    }
  196. }
  197.